package com.source.hotelbath.fragment;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.source.hotelbath.R;
import com.source.hotelbath.activity.LinenListActivity;
import com.source.hotelbath.activity.OrderDeatilActivity;
import com.source.hotelbath.base.CustomerAdapter;
import com.source.hotelbath.model.OrderListBean;
import com.source.hotelbath.net.response.OrderListResponse;
import com.source.hotelbath.utils.DateUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ZhouMeng on 2017/9/26.
 */

public class DoneItemAdapter extends CustomerAdapter {

    private Context mContext;
    private List<OrderListBean> orderList=new ArrayList<>();

    public DoneItemAdapter(Context context, List<OrderListBean> orderList) {
        this.mContext=context;
        this.orderList=orderList;
    }

    @Override
    public int getCount() {
        return orderList.size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

           ViewHolder holder;
            if (null == convertView) {
                holder = new ViewHolder();
                convertView = LayoutInflater.from(mContext).inflate(R.layout.undone_item, null);
                holder.tv_num = (TextView) convertView.findViewById(R.id.tv_num);
                holder.tv_data = (TextView) convertView.findViewById(R.id.tv_data);
                holder.tv_price = (TextView) convertView.findViewById(R.id.tv_price);
                holder.tv_hotel = (TextView) convertView.findViewById(R.id.tv_hotel);
                holder.ll_bg= (LinearLayout) convertView.findViewById(R.id.ll_bg);
                holder.textView2= (TextView) convertView.findViewById(R.id.textView2);
//                ViewGroup.LayoutParams params=  holder.ivPic1.getLayoutParams();
//                params.height= (PhoneDisplay.SCREEN_WIDTH_PIXELS- PhoneDisplay.dp2px(16)*2)*2/9;
//                params.width=(PhoneDisplay.SCREEN_WIDTH_PIXELS- PhoneDisplay.dp2px(16)*2)/3;
//                holder.ivPic1.setLayoutParams(params);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            holder.tv_num.setText(orderList.get(position).getGoodsNum()+"");
            holder.tv_data.setText(DateUtils.getDateToString(orderList.get(position).getOrderTime().getTime()));
            holder.tv_price.setText("￥"+orderList.get(position).getOrderMoney());
           holder.tv_hotel.setText(orderList.get(position).getHotelName());
           if (orderList.get(position).getOrderState().equals("04")){
               holder.ll_bg.setBackgroundResource(R.drawable.green_right);
               holder.textView2.setText("已收布草");
           }else {
               holder.ll_bg.setBackgroundResource(R.drawable.orger_right);
               holder.textView2.setText("已取布草");
           }


        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, OrderDeatilActivity.class);
                intent.putExtra("orderId",orderList.get(position).getId());
                intent.putExtra("status",orderList.get(position).getOrderState());
                mContext.startActivity(intent);
            }
        });


        return convertView;
    }

    class ViewHolder {
        TextView tv_num;
        TextView tv_data;
        TextView tv_price;
        TextView tv_hotel;
        TextView textView2;

        LinearLayout ll_bg;

    }
}
